package cn.zwx.member.svc.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.zwx.common.mybatis.query.LambdaQueryWrapperX;
import cn.zwx.member.svc.domain.entity.MemberDistrictsEntity;
import cn.zwx.member.svc.dto.DsitrictsListDTO;
import cn.zwx.member.svc.mapper.MemberDistrictsMapper;
import cn.zwx.member.svc.service.DsitrictsService;
import cn.zwx.member.svc.vo.DsitrictsListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangwenxue
 */
@Service
public class DsitrictsServiceImpl implements DsitrictsService {

    @Resource
    private MemberDistrictsMapper mapper;
    @Override
    public List<DsitrictsListVO> getDistrictsList(DsitrictsListDTO dto) {
        // 1.查询信息
        LambdaQueryWrapperX<MemberDistrictsEntity> wrapperX = new LambdaQueryWrapperX<>();
        wrapperX.eq(MemberDistrictsEntity::getDistrictPid, dto.getDistrictsId());
        List<MemberDistrictsEntity> selectList = mapper.selectList(wrapperX);
        // 2.返回参数
        if (CollUtil.isEmpty(selectList)){
            return new ArrayList<>();
        }
        List<DsitrictsListVO> returnList = new ArrayList<>();
        selectList.forEach(t->{
            final DsitrictsListVO dsitrictsListVO = new DsitrictsListVO();
            BeanUtils.copyProperties(t,dsitrictsListVO);
            dsitrictsListVO.setCityCode(t.getCityCode());
            returnList.add(dsitrictsListVO);
        });
        return returnList;
    }
}
